package com.liu.security.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shi860715@126.com
 * Date 2021/8/11 10:46
 * 测试安全框架
 */
@RestController
public class TestController {

      @GetMapping("/test")
      public String test(){
          return "test";
      }


    @GetMapping("/home")
    public String home(){
        return "这里是主页";
    }

    @GetMapping("/hasRoleAdmin")
    @Secured("ROLE_admin")
    public String hasRoleAdmin(){
        return "拥有权限admin才能看到";
    }

    @GetMapping("/hasRoleTest")
    @Secured("test")
    public String hasRoleTest(){
        return "拥有权限test才能看到";
    }


    @GetMapping("/hasRoleTest1")
    @PreAuthorize("hasAnyAuthority('test')")
    public String hasRoleTest1(){
        return "拥有权限test才能看到";
    }

    @GetMapping("/hasRoleTest2")
    @PreAuthorize("hasAnyAuthority('user:add')")
    public String hasAnyAuthority(){
        return "拥有权限user:add才能看到";
    }

    @GetMapping("/hasRoleTest3")
    @PreAuthorize("hasPermission('user:add')")
    public String hasPermission(){
        return "拥有权限user:add才能看到";
    }

}
